package com.ruoyi.web.controller.coronary;

import java.util.List;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.coronary.domain.CoronaryMessage;
import com.ruoyi.coronary.service.ICoronaryMessageService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;

/**
 * 消息Controller
 *
 * @author wky
 * @date 2024-04-09
 */
@RestController
@RequestMapping("/coronary/message")
@Tag(name = "【消息】管理")
public class CoronaryMessageController extends BaseController
{
    @Autowired
    private ICoronaryMessageService coronaryMessageService;

    /**
     * 查询消息列表
     */
    @Operation(summary = "查询消息列表")
    @PreAuthorize("@ss.hasPermi('coronary:message:list')")
    @GetMapping("/list")
    public TableDataInfo list(CoronaryMessage coronaryMessage)
    {
        startPage();
        List<CoronaryMessage> list = coronaryMessageService.selectCoronaryMessageList(coronaryMessage);
        return getDataTable(list);
    }

    /**
     * 导出消息列表
     */
    @Operation(summary = "导出消息列表")
    @PreAuthorize("@ss.hasPermi('coronary:message:export')")
    @Log(title = "消息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CoronaryMessage coronaryMessage)
    {
        List<CoronaryMessage> list = coronaryMessageService.selectCoronaryMessageList(coronaryMessage);
        ExcelUtil<CoronaryMessage> util = new ExcelUtil<CoronaryMessage>(CoronaryMessage.class);
        util.exportExcel(response, list, "消息数据");
    }

    /**
     * 获取消息详细信息
     */
    @Operation(summary = "获取消息详细信息")
    @PreAuthorize("@ss.hasPermi('coronary:message:query')")
    @GetMapping(value = "/{messageId}")
    public AjaxResult getInfo(@PathVariable("messageId") Long messageId)
    {
        return success(coronaryMessageService.selectCoronaryMessageByMessageId(messageId));
    }

    /**
     * 新增消息
     */
    @Operation(summary = "新增消息")
    @PreAuthorize("@ss.hasPermi('coronary:message:add')")
    @Log(title = "消息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CoronaryMessage coronaryMessage)
    {
        return toAjax(coronaryMessageService.insertCoronaryMessage(coronaryMessage));
    }

    /**
     * 修改消息
     */
    @Operation(summary = "修改消息")
    @PreAuthorize("@ss.hasPermi('coronary:message:edit')")
    @Log(title = "消息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CoronaryMessage coronaryMessage)
    {
        return toAjax(coronaryMessageService.updateCoronaryMessage(coronaryMessage));
    }

    /**
     * 删除消息
     */
    @Operation(summary = "删除消息")
    @PreAuthorize("@ss.hasPermi('coronary:message:remove')")
    @Log(title = "消息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{messageIds}")
    public AjaxResult remove(@PathVariable( name = "messageIds" ) Long[] messageIds)
    {
        return toAjax(coronaryMessageService.deleteCoronaryMessageByMessageIds(messageIds));
    }
}
